/**
 * 带有(可选)箭头指向的基础弹层，由STK.rtEditor.mod.layer衍生
 * 拥有全部STK.rtEditor.mod.layer的函数
 * @author ZhouJiequn | jiequn@staff.sina.com.cn
 */
$Import('app.common.layer');
STK.register('app.common.bubbleLayer', function($){
	var template = 
		'<div node-type="outer" class="bubbleLayer" style="display:none;">'+
			'<div node-type="inner" style="margin:5px;"></div>'+
		'</div>';
	/**
	 * @param {String} con 弹出层内容
	 */
	return function(con){
		var layer, box, content, that;
		var setPostion = function(pos){
			box.style.top = pos['t'] + 'px';
			box.style.left = pos['l'] + 'px';
			return that;
		};
		
		var setMiddle = function(){
			var win = $.core.util.winSize();
			var dia = layer.getSize(true);
			box.style.top	= $.core.util.scrollPos()['top'] + (win.height - dia.h)/2 + 'px';
			box.style.left	= (win.width - dia.w)/2 + 'px';
			return that;
		};
		
		var setContent = function(cont){
			if(typeof cont === 'string'){
				content.innerHTML = cont;
			}else{
				content.appendChild(cont);
			}
			return that;
		};

		var init = function(){
			layer	= $.app.common.layer(template);
			box 	= layer.getOuter();
			content	= layer.getDom('inner');
			that 	= layer;
			con && setContent(con);
			document.body.appendChild(box);
		};
		init();
		that.setPostion	= setPostion;
		that.setMiddle	= setMiddle;
		that.setContent	= setContent;
		return that;
	};
});